package screenpac.controllers;
/**
 * Luis Cruz
 * GAME AI Milestone 1
 */
import java.util.ArrayList;

import screenpac.extract.Constants;
import screenpac.features.NearestPillDistance;
import screenpac.features.Utilities;
import screenpac.model.GameStateInterface;
import screenpac.model.Node;

public class GaiSuperRandomM1 implements AgentInterface, Constants{

	NearestPillDistance npd;
	Node prev;
	
	public GaiSuperRandomM1() {
		npd = new NearestPillDistance();
	}
	
		
	public int action(GameStateInterface gs) {
		Node current = gs.getPacman().current;
		float random = rand.nextFloat();
		int dir = 0;
		if(random < 0.2) {
			//Go to nearest pill
			npd.score(gs, current);
			Node next = Utilities.getClosest(current.adj, npd.closest, gs.getMaze());
			prev = current;
			dir = Utilities.getWrappedDirection(current, next, gs.getMaze());
		} else {
			//Got to random Non Reverse
			ArrayList<Node> futureNodes= new ArrayList();
			for(Node n: current.adj) {
				if(!n.equals(prev)) {
					futureNodes.add(n);
				}
			}
			Node next = futureNodes.get(rand.nextInt(futureNodes.size()));
			prev = current;
			dir = Utilities.getWrappedDirection(current, next, gs.getMaze());
		}
		return dir;
	}

}
